'''
@author: Chase Miller

A recursive decent parser.

Assignment 1 - CS 550

'''
import sys, os
import __builtin__ as builtin
import re

inputChars = None
inputAsString = ''
currentIndex = 0
Token = None
internalList = None

LIST_START_TERM = "("
LIST_END_TERM = ')'
SEQUENCE_SEPARATOR = ','
NUMBER = re.compile(r"[0-9]+")


def getToken():
    '''
    Advances to and returns the next token
    '''
    global currentIndex
    global Token        
    
    currentIndex += 1
    
    if(currentIndex < len(inputChars)):
        Token = inputChars[currentIndex]
    
    return Token

def match(token):
    '''
    Matches the next token (by calling getToken()), or errors if no match.
    '''
    global Token
    global NUMBER
    
    shouldContinue = False
    
    isNumber = (token == NUMBER)

    if(isNumber == False):
        if(token == Token):
            internalList.append(Token)
            return getToken()
        else:
            errorAndExit()
    else:
        if (re.match(token, Token) != None):
            internalList.append(findFullNumber())
        else:
            errorAndExit()
    
def errorAndExit():
    '''
    Prints an error message and exists the program
    '''
    print('-error-')
    exit()

def findFullNumber():
    '''
    Finds all the numbers until there are none left, updating currentIndex and Token as appropriate
    '''
    fullNumber = Token
    while(re.match(NUMBER, getToken()) != None):
        fullNumber += Token
    
    return fullNumber

def list():
    '''
    Parses a list
    '''
    match(LIST_START_TERM)
    if(Token != LIST_END_TERM):
        seq()
    match(LIST_END_TERM)

def listElement():
    '''
    Parses a list element
    '''
    if (Token == LIST_START_TERM):
        list()
    else:
        match(NUMBER)
        
def seq():
    '''
    Parses a sequence
    ''' 
    listElement()
    if(Token == SEQUENCE_SEPARATOR):
        match(SEQUENCE_SEPARATOR)
        seq()
        
def printDataStructure():
    '''
    Prints the data structure, in the same format that was read, on a single line, to stdout, to verify correctness.
    '''
    listToPrint = ''
    for next in internalList:
        listToPrint += next
        
    print listToPrint

if __name__ == '__main__':
    
    if(os.fstat(sys.stdin.fileno()).st_size > 0):
    
        internalList = builtin.list()
        
        for line in sys.stdin:
            inputAsString += line.replace("\n", "")
        
        cleanedString = inputAsString.replace(" ", "").replace("\t", "")
        inputChars = builtin.list(cleanedString)
        Token = inputChars[0]
        
        list()
        
        printDataStructure()
    else:
        print 'Usage: please supply stdin'
        exit()